import request from '@/utils/request.js'

// 登录接口函数的封装
export function loginApi (data) {
  return request({
    method: 'post',
    url: '/login',
    data
  })
}

// 获取 menus菜单函数
export function menusApi () {
  return request({
    method: 'get',
    url: '/menus'
    // headers: {
    //   Authorization: localStorage.getItem('token')
    // }
  })
}

// 获取 用户数据列表
export function usersApi (params) {
  return request({
    method: 'get',
    url: '/users',
    params
  })
}

/* 添加用户数据列表 */
export function addUsersApi (params) {
  return request({
    method: 'post',
    url: '/users',
    data: params
  })
}

/* 删除用户数据列表 */
export function delUsersApi (id) {
  return request({
    method: 'delete',
    url: `/users/${id}`
  })
}

/* 编辑用户数据列表 */
export function editUsersApi (obj) {
  return request({
    method: 'put',
    url: `/users/${obj.id}`,
    data: {
      email: obj.email,
      mobile: obj.mobile
    }
  })
}

/* 更改状态 */
export function editStateUsersApi (id, state) {
  return request({
    method: 'put',
    url: `users/${id}/state/${state}`
  })
}

/* 获取商品分类数据 */
export function goodsCateApi (params) {
  return request({
    method: 'get',
    url: 'categories',
    params: params
  })
}

/* 获取参数数据 */
export function paramsApi (obj) {
  return request({
    method: 'get',
    url: `categories/${obj.id}/attributes`,
    params: {
      sel: obj.sel
    }
  })
}

/* 添加参数属性 */
export function addParamsAttrApi (obj) {
  return request({
    method: 'put',
    url: `categories/${obj.id}/attributes/${obj.attrId}`,
    data: {
      attr_name: obj.attr_name,
      attr_sel: obj.attr_sel,
      attr_vals: obj.attr_vals
    }
  })
}
